home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase v5.5 / SAMPLES2.PAK / PAINT.WFM < prev    next >
Encoding:
Text File  |  1995-07-18  |  18.6 KB  |  655 lines

  1. *******************************************************************************
  2. *  PROGRAM:      Paint.wfm
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         4/94
  7. *
  8. *  UPDATED:      5/95
  9. *
  10. *  REVISION:     $Revision:   1.5  $
  11. *
  12. *  VERSION:      Visual dBASE
  13. *
  14. *  DESCRIPTION:  This program demonstrates the use of the paintbox and shapes
  15. *                controls by allowing you to select an image from a table or
  16. *                from a .bmp file, and combine it with an existing/previous
  17. *                image.
  18. *
  19. *  PARAMETERS:   None
  20. *
  21. *  CALLS:        Buttons.cc      (Custom Controls file)
  22. *
  23. *  USAGE:        DO Paint.wfm
  24. *
  25. ********************************************************************************
  26. #include <winapi.h>
  27. #define NUM_RASTER_OPS  6
  28.  
  29. *** Environment
  30. create session
  31. set talk off
  32. set fullpath off
  33.  
  34. ** END HEADER -- do not remove this line*
  35. * Generated on 07/18/95
  36. *
  37. parameter bModal
  38. local f
  39. f = new PAINTFORM()
  40. if (bModal)
  41.    f.mdi = .F. && ensure not MDI
  42.    f.ReadModal()
  43. else
  44.    f.Open()
  45. endif
  46. CLASS PAINTFORM OF FORM
  47.    Set Procedure To BUTTONS.CC additive
  48.    this.OnOpen = CLASS::FORM_ONOPEN
  49.    this.OnClose = CLASS::FORM_ONCLOSE
  50.    this.Text = "Image Painter"
  51.    this.OnNavigate = CLASS::FORM_ONNAVIGATE
  52.    this.Top = 0.2344
  53.    this.Left = 15
  54.    this.OnSize = CLASS::FORM_ONSIZE
  55.    this.ColorNormal = "N/BTNFACE"
  56.    this.Height = 17.7051
  57.    this.Width = 58.666
  58.  
  59.    DEFINE SHAPE SHAPE1 OF THIS;
  60.        PROPERTY;
  61.          ShapeStyle 0,;
  62.          Top 0.5,;
  63.          PenWidth 1,;
  64.          Left 1,;
  65.          ColorNormal "B/BTNFACE",;
  66.          Height 4.3232,;
  67.          Width 57
  68.  
  69.    DEFINE SHAPE RADIOSHAPE OF THIS;
  70.        PROPERTY;
  71.          Visible .F.,;
  72.          ShapeStyle 2,;
  73.          Top 1.6973,;
  74.          PenWidth 2,;
  75.          Left 7,;
  76.          ColorNormal "B/BTNFACE",;
  77.          Height 1.7139,;
  78.          Width 12
  79.  
  80.    DEFINE LINE LINE1 OF THIS;
  81.        PROPERTY;
  82.          Top 5.4,;
  83.          Bottom 5.4,;
  84.          Right 2,;
  85.          Left 57,;
  86.          ColorNormal "GB+/BTNFACE",;
  87.          Width 1
  88.  
  89.    DEFINE LINE LINE2 OF THIS;
  90.        PROPERTY;
  91.          Top 5.6065,;
  92.          Bottom 5.6065,;
  93.          Right 3,;
  94.          Left 55.6065,;
  95.          ColorNormal "RG+/BTNFACE",;
  96.          Width 1
  97.  
  98.    DEFINE LINE LINE3 OF THIS;
  99.        PROPERTY;
  100.          Top 5.8529,;
  101.          Bottom 5.8529,;
  102.          Right 4.3333,;
  103.          Left 53.6667,;
  104.          ColorNormal "B+/BTNFACE",;
  105.          Width 1
  106.  
  107.    DEFINE SHAPE OPERATIONSHAPE OF THIS;
  108.        PROPERTY;
  109.          ShapeStyle 0,;
  110.          Top 6.5,;
  111.          PenWidth 1,;
  112.          Left 1.8311,;
  113.          ColorNormal "B/BTNFACE",;
  114.          Height 2.0293,;
  115.          Width 55.002
  116.  
  117.    DEFINE SHAPE SRCSHAPE OF THIS;
  118.        PROPERTY;
  119.          ShapeStyle 0,;
  120.          Top 9.5293,;
  121.          PenWidth 1,;
  122.          Left 2.1982,;
  123.          ColorNormal "B/BTNFACE",;
  124.          Height 5.8818,;
  125.          Width 23.6348
  126.  
  127.    DEFINE SHAPE DSTSHAPE OF THIS;
  128.        PROPERTY;
  129.          ShapeStyle 0,;
  130.          Top 9.5293,;
  131.          PenWidth 1,;
  132.          Left 33,;
  133.          ColorNormal "B/BTNFACE",;
  134.          Height 5.8818,;
  135.          Width 23.666
  136.  
  137.    DEFINE TEXT SELECTTEXT OF THIS;
  138.        PROPERTY;
  139.          FontItalic .T.,;
  140.          Text "Select Source Bitmap: ",;
  141.          Top 0.1875,;
  142.          Left 19,;
  143.          ColorNormal "B+/BTNFACE",;
  144.          Height 0.7529,;
  145.          Width 18.5,;
  146.          FontBold .F.
  147.  
  148.    DEFINE TOOLBUTTON IMAGETOOLBUTTON OF THIS;
  149.        PROPERTY;
  150.          Group .F.,;
  151.          OnClick CLASS::SELECTBINARY,;
  152.          Top 1.8223,;
  153.          Left 2.5,;
  154.          Height 1.2949,;
  155.          Width 4
  156.  
  157.    DEFINE RADIOBUTTON BINARYRADIO OF THIS;
  158.        PROPERTY;
  159.          Group .T.,;
  160.          Text "Binary",;
  161.          OnChange CLASS::BINARYRADIO_ONCHANGE,;
  162.          Top 2.0977,;
  163.          Left 8.5,;
  164.          Value .T.,;
  165.          ColorNormal "B/BTNFACE",;
  166.          Height 0.8428,;
  167.          Width 9,;
  168.          FontBold .F.
  169.  
  170.    DEFINE RADIOBUTTON FILERADIO OF THIS;
  171.        PROPERTY;
  172.          Group .F.,;
  173.          Text "File",;
  174.          OnChange CLASS::FILERADIO_ONCHANGE,;
  175.          Top 3.3975,;
  176.          Left 8.5,;
  177.          Value .F.,;
  178.          ColorNormal "B/BTNFACE",;
  179.          Height 0.8965,;
  180.          Width 7,;
  181.          FontBold .F.
  182.  
  183.    DEFINE TEXT FIELDNAMETEXT OF THIS;
  184.        PROPERTY;
  185.          FontItalic .T.,;
  186.          Text "Field Name:",;
  187.          Top 1.1973,;
  188.          Left 20,;
  189.          ColorNormal "N+/BTNFACE",;
  190.          Height 0.8027,;
  191.          Width 12.5,;
  192.          FontBold .F.
  193.  
  194.    DEFINE COMBOBOX FIELDNAMECOMBO OF THIS;
  195.        PROPERTY;
  196.          OnOpen CLASS::FIELDNAMECOMBO_ONCHANGE,;
  197.          FontSize 7,;
  198.          OnChange CLASS::FIELDNAMECOMBO_ONCHANGE,;
  199.          Top 2,;
  200.          Style 1,;
  201.          Left 20,;
  202.          ColorNormal "B/GB+",;
  203.          Height 1,;
  204.          FontName "MS Serif",;
  205.          Width 22,;
  206.          FontBold .F.
  207.  
  208.    DEFINE TEXT RECNOTEXT OF THIS;
  209.        PROPERTY;
  210.          FontItalic .T.,;
  211.          Text "Record No: ",;
  212.          Top 1.1973,;
  213.          Left 45,;
  214.          ColorNormal "N+/BTNFACE",;
  215.          Height 0.8027,;
  216.          Width 11.5,;
  217.          FontBold .F.
  218.  
  219.    DEFINE SPINBOX RECNOSPIN OF THIS;
  220.        PROPERTY;
  221.          Rangemax 100,;
  222.          OnChange CLASS::RECNOSPIN_ONCHANGE,;
  223.          Top 2,;
  224.          Left 45,;
  225.          Value 1,;
  226.          Rangemin 1,;
  227.          ColorNormal "B/GB+",;
  228.          Picture "9999",;
  229.          Height 1,;
  230.          RangeRequired .T.,;
  231.          FontName "MS Serif",;
  232.          Width 11
  233.  
  234.    DEFINE ENTRYFIELD FILEENTRY OF THIS;
  235.        PROPERTY;
  236.          Visible .F.,;
  237.          Top 3.3975,;
  238.          Enabled .F.,;
  239.          Left 20,;
  240.          Value "",;
  241.          ColorNormal "B/GB+",;
  242.          Height 1.0137,;
  243.          Width 36
  244.  
  245.    DEFINE TEXT OPERATIONTEXT OF THIS;
  246.        PROPERTY;
  247.          FontItalic .T.,;
  248.          Text "Raster Operation: ",;
  249.          Top 6.1973,;
  250.          Left 21.5,;
  251.          ColorNormal "B+/BTNFACE",;
  252.          Height 0.7432,;
  253.          Width 15.5,;
  254.          FontBold .F.
  255.  
  256.    DEFINE COMBOBOX RASTEROPCOMBO OF THIS;
  257.        PROPERTY;
  258.          DropDownHeight 4,;
  259.          FontSize 7,;
  260.          ID 102,;
  261.          OnChange CLASS::RASTEROPCOMBO_ONSELCHANGE,;
  262.          Top 7.0977,;
  263.          Style 2,;
  264.          Left 9.3311,;
  265.          ColorNormal "B/GB+",;
  266.          Height 1.0195,;
  267.          FontName "MS Serif",;
  268.          Width 40.002,;
  269.          FontBold .F.
  270.  
  271.    DEFINE TEXT SOURCETEXT OF THIS;
  272.        PROPERTY;
  273.          FontItalic .T.,;
  274.          Text "Source:",;
  275.          Top 9.1973,;
  276.          Left 10,;
  277.          ColorNormal "B+/BTNFACE",;
  278.          Height 0.7432,;
  279.          Width 8.333,;
  280.          FontBold .F.
  281.  
  282.    DEFINE IMAGE SRCIMAGE OF THIS;
  283.        PROPERTY;
  284.          DataSource "",;
  285.          Top 10,;
  286.          Left 4,;
  287.          Height 5,;
  288.          Width 20
  289.  
  290.    DEFINE TEXT DESTINATIONTEXT OF THIS;
  291.        PROPERTY;
  292.          FontItalic .T.,;
  293.          Text "Destination: ",;
  294.          Top 9.1973,;
  295.          Left 40,;
  296.          ColorNormal "B+/BTNFACE",;
  297.          Height 0.7432,;
  298.          Width 11.666,;
  299.          FontBold .F.
  300.  
  301.    DEFINE PAINTBOX DSTPAINTBOX OF THIS;
  302.        PROPERTY;
  303.          OnPaint CLASS::DSTPAINTBOX_ONPAINT,;
  304.          Top 10,;
  305.          Left 35,;
  306.          Height 5,;
  307.          ColorNormal "WindowText/Window",;
  308.          Width 20
  309.  
  310.    DEFINE CLOSEBUTTON CLOSEBUTTON1 OF THIS;
  311.        PROPERTY;
  312.          Group .T.,;
  313.          Top 16,;
  314.          Left 22.1641,;
  315.          Height 1.5293,;
  316.          Width 14.1689,;
  317.          FontBold .F.
  318.  
  319.    DEFINE SAMPLEINFOBUTTON PAINTINFOBUTTON OF THIS;
  320.        PROPERTY;
  321.          Group .T.,;
  322.          Top 16.3975,;
  323.          Left 55,;
  324.          Height 1.1904,;
  325.          Width 3.5
  326.  
  327.    Procedure Form_OnOpen
  328.    ****************************************************************************
  329.  
  330.    * Arrays for describing and executing raster operations
  331.    form.opDescriptAr = new array(NUM_RASTER_OPS) && Raster op descriptions
  332.    form.rasterOpAr = new assocArray()            && Raster operations
  333.  
  334.    form.binaryFldAr = new array(0)               && Binary field names
  335.  
  336.    form.opDescriptAr[1] = "Copy Source to Destination"
  337.    form.opDescriptAr[2] = "Merge Source with Destination"
  338.    form.opDescriptAr[3] = "Invert Destination"
  339.    form.opDescriptAr[4] = "Copy inverted Source to Destination"
  340.    form.opDescriptAr[5] = "Merge inverted Source with Destination"
  341.    form.opDescriptAr[6] = "Clear out Destination"
  342.  
  343.    form.rasterOpCombo.DataSource = "array form.opDescriptAr"
  344.  
  345.    form.rasterOpAr["Copy Source to Destination"]               = SRCCOPY
  346.    form.rasterOpAr["Merge Source with Destination"]            = SRCAND
  347.    form.rasterOpAr["Invert Destination"]                       = DSTINVERT
  348.    form.rasterOpAr["Copy inverted Source to Destination"]      = NOTSRCCOPY
  349.    form.rasterOpAr["Merge inverted Source with Destination"]   = SRCINVERT
  350.    form.rasterOpAr["Clear out Destination"]                    = WHITENESS
  351.  
  352.    form.rasterOpCombo.value = form.opDescriptAr[1]
  353.    form.fieldNameCombo.value = ""  && Form designer doesn't allow empty value
  354.    form.paintInfoButton.sampleName = "Paint.wfm"
  355.  
  356.    ****************************************************************************
  357.  
  358.    Procedure Form_OnClose
  359.    ****************************************************************************
  360.  
  361.    use                                  && If table had been selected, close it
  362.    close procedure Buttons.cc
  363.  
  364.    ****************************************************************************
  365.  
  366.    Procedure DstPaintBox_Clear
  367.    ****************************************************************************
  368.    private hDcPaintbox, iResult
  369.  
  370.    hDcPaintBox = GetDc(form.dstPaintBox.hWnd)       && Paint Box device context
  371.    iResult = BitBlt(hDcPaintBox, 0, 0, 200, 200, 0, 0, 0, WHITENESS)  && White
  372.    iResult = ReleaseDc(form.dstPaintBox.hWnd, hDcPaintBox)  && Get memory back
  373.  
  374.  
  375.    ****************************************************************************
  376.  
  377.    Procedure DSTPAINTBOX_OnPaint
  378.    ****************************************************************************
  379.    local i, paintStruct
  380.     private hDcPaintbox, hDcImage, hImage, iResult, iRasterOp
  381.  
  382.    * Ensure paint occurs for image source first
  383.    UpdateWindow(form.srcimage.hWnd)
  384.  
  385.    paintStruct = space(32)
  386.    hDC = BeginPaint(this.hwnd, paintStruct)
  387.  
  388.    hImage = form.srcImage.hWnd                  && Source Image handle
  389.    hDcImage = GetDc(hImage)                     && Source Image device context
  390.                                                 && Retrieve raster operation
  391.    iRasterOp = form.rasterOpAr[form.rasterOpCombo.value]  && Don't use this in
  392.                                                 && case function called from
  393.                                                 && another control
  394.  
  395.    * Do it
  396.    iResult = BitBlt(hDc, 0, 0, 200, 200, hDcImage, 0, 0, iRasterOp)
  397.  
  398.    iResult = ReleaseDc(form.dstPaintBox.hWnd, hDcImage)     && Get memory back
  399.  
  400.    EndPaint(paintStruct)
  401.  
  402.    for i = 1 to 1000                            && Do some funcky thing
  403.       form.dstShape.penwidth = 3
  404.       form.dstShape.penwidth = 1
  405.    next i
  406.  
  407.  
  408.    ****************************************************************************
  409.  
  410.    Procedure RASTEROPCOMBO_OnSelChange
  411.    ****************************************************************************
  412.  
  413.    invalidateRect (form.dstPaintBox.hwnd, 0, .F. )
  414.  
  415.    ****************************************************************************
  416.  
  417.    Procedure BINARYRADIO_OnChange
  418.    ****************************************************************************
  419.  
  420.    if this.value                        && If this button is selected
  421.       CLASS::ShowBinaryControls()
  422.       CLASS::ShowFileControls()
  423.  
  424.       form.fieldNameCombo.OnChange()    && Enable/disable controls if necessary
  425.       form.imageToolButton.OnClick = CLASS::SelectBinary
  426.       form.imageToolButton.top = 1.832
  427.    endif
  428.  
  429.  
  430.    ****************************************************************************
  431.  
  432.    Procedure FILERADIO_OnChange
  433.    ****************************************************************************
  434.  
  435.    if this.value                        && If this button is selected
  436.       CLASS::ShowFileControls()
  437.       CLASS::ShowBinaryControls()
  438.  
  439.       form.imageToolButton.OnClick = CLASS::SelectFile
  440.       form.imageToolButton.top = 3.2
  441.    endif
  442.  
  443.    ****************************************************************************
  444.  
  445.    Procedure RECNOSPIN_OnChange
  446.    ****************************************************************************
  447.  
  448.    go this.value                        && Go to record specified in spinbox
  449.  
  450.  
  451.    ****************************************************************************
  452.  
  453.    Procedure FIELDNAMECOMBO_OnChange
  454.    ****************************************************************************
  455.  
  456.    if empty(this.value)                 && If no binary fields available,
  457.       this.enabled = .F.
  458.       form.recNoSpin.enabled = .F.      && make record selection not available
  459.    else                                 && Otherwise
  460.       this.enabled = .T.
  461.       form.srcImage.dataSource = "binary " + this.value && Update image
  462.       form.recNoSpin.enabled = .T.      && Make record selection available
  463.    endif
  464.  
  465.  
  466.    ****************************************************************************
  467.  
  468.    Procedure SelectBinary
  469.    ****************************************************************************
  470.    private tableName, fieldCount, fieldName
  471.  
  472.    tableName = getfile("*.dbf", "Select a table")
  473.    if .not. empty(tableName)            && A table was actually selected
  474.       CLASS::ClearFileControls()        && Clear out file controls
  475.  
  476.       form.radioShape.top = 1.7
  477.       form.radioShape.visible = .T.
  478.       use (tableName)                   && Table
  479.       fieldCount = fCount()
  480.       form.binaryFldAr = new array(0)
  481.       for i = 1 to fieldCount
  482.          fieldName = field(i)
  483.          if type(fieldName) = "B"       && If Binary field
  484.             form.binaryFldAr.Add(CLASS::GetTableName(dbf()) + "->" + fieldName)
  485.          endif
  486.       next i
  487.       form.fieldNameCombo.value = ""
  488.       form.fieldNameCombo.dataSource = "array form.binaryFldAr"
  489.       * form.fieldNameCombo.visible = .T.
  490.       form.fieldNameCombo.OnChange()
  491.  
  492.       form.recNoSpin.value = 1
  493.       form.recNoSpin.rangeMax = reccount()
  494.       * form.recNoSpin.visible = .T.
  495.       CLASS::ShowBinaryControls()
  496.    endif
  497.  
  498.  
  499.    ****************************************************************************
  500.  
  501.    Procedure SelectFile
  502.    ****************************************************************************
  503.    local fileName
  504.  
  505.    fileName = getFile("*.bmp", "Select a bitmap file")
  506.    if .not. empty(fileName)             && If file was actually selected
  507.       CLASS::ClearBinaryControls()      && Clear out binary controls
  508.  
  509.       * Set up image from file
  510.       form.radioShape.top = 3           && Move highlight on this radiobutton
  511.       form.radioShape.visible = .T.     && Make visible (initially it is not)
  512.       form.fileEntry.value = fileName   && Show selected file
  513.       show object form.fileEntry        && (Really visible)
  514.       form.srcImage.dataSource = "file " + fileName  && Show image in file
  515.       CLASS::ShowFileControls()
  516.    endif
  517.  
  518.  
  519.  
  520.    ****************************************************************************
  521.  
  522.    Function GetTableName(dbf)
  523.    ****************************************************************************
  524.    local strippedName, periodLoc
  525.  
  526.    * Strip drive
  527.    strippedName = substr(dbf, at(":", dbf) + 1)
  528.  
  529.    * Strip extension
  530.    periodLoc = rat(".", strippedName)
  531.    if periodLoc > 0                && dbf has an extension
  532.       strippedName = left(strippedName, periodLoc - 1)
  533.    endif
  534.  
  535.    return strippedName
  536.  
  537.  
  538.    ****************************************************************************
  539.  
  540.    Procedure ShowBinaryControls
  541.    ****************************************************************************
  542.    local notEmptyFieldName
  543.  
  544.    notEmptyFieldName = .not. empty(form.fieldNameCombo.value)
  545.    if form.fileRadio.value              && If File radio button is selected
  546.  
  547.       * Only show these controls if they are connected to data
  548.       form.fieldNameText.visible = notEmptyFieldName
  549.       form.fieldNameCombo.visible = notEmptyFieldName
  550.       form.recNoText.visible = notEmptyFieldName
  551.       form.recNoSpin.visible = notEmptyFieldName
  552.  
  553.       * Disable binary selection controls when fileRadio button is selected
  554.       form.fieldNameCombo.enabled = .F.
  555.       form.recNoSpin.enabled = .F.
  556.  
  557.    else                                 && If Binary radio button is selected
  558.       form.fieldNameText.visible = .T.
  559.       form.fieldNameCombo.visible = .T.
  560.       form.recNoText.visible = .T.
  561.       form.recNoSpin.visible = .T.
  562.  
  563.       form.fieldNameCombo.enabled = notEmptyFieldName
  564.       form.recNoSpin.enabled = notEmptyFieldName
  565.  
  566.    endif
  567.  
  568.  
  569.    ****************************************************************************
  570.  
  571.    Procedure ClearBinaryControls
  572.    ****************************************************************************
  573.  
  574.    * Make controls invisible
  575.    form.fieldNameText.visible = .F.
  576.    form.fieldNameCombo.visible = .F.
  577.    form.recNoText.visible = .F.
  578.    form.recNoSpin.visible = .F.
  579.  
  580.    * Clear out values
  581.    form.fieldNameCombo.dataSource = ""
  582.    form.fieldNameCombo.value = ""
  583.    form.recNoSpin.value = 1
  584.  
  585.    * Close table, if it is open
  586.    use
  587.  
  588.  
  589.    ****************************************************************************
  590.  
  591.    Procedure ShowFileControls
  592.    ****************************************************************************
  593.    private notEmptyFileName
  594.  
  595.    notEmptyFileName = .not. empty(form.fileEntry.value)
  596.    if form.binaryRadio.value            && If Binary radio button is selected
  597.       form.fileEntry.visible = notEmptyFileName
  598.    else                                 && If File radio button is selected
  599.       form.fileEntry.visible = .T.
  600.    endif
  601.    show object form.fileEntry
  602.  
  603.  
  604.    ****************************************************************************
  605.  
  606.    Procedure ClearFileControls
  607.    ****************************************************************************
  608.  
  609.    form.fileEntry.visible = .F.
  610.    form.fileEntry.value = ""
  611.  
  612.  
  613.    ****************************************************************************
  614.  
  615.    Procedure Form_OnSize(sizeType, width, height)
  616.    ****************************************************************************
  617.  
  618.    form.height = 17.71
  619.    form.width = 58.67
  620.  
  621.    Procedure Form_OnNavigate(nWorkArea)
  622.    invalidateRect (form.dstPaintBox.hwnd, 0, .F. )
  623.  
  624. ENDCLASS
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.